package com.opensource.component.query.configuration;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.opensource.component.query.method.ClickhouseExtendDelete;
import com.opensource.component.query.method.ClickhouseExtendInsertOne;
import com.opensource.component.query.method.ClickhouseExtendSelectCount;
import com.opensource.component.query.method.ClickhouseExtendSelectList;
import com.opensource.component.query.method.ClickhouseExtendSelectPage;
import com.opensource.component.query.method.ClickhouseExtendUpdate;
import com.opensource.component.query.method.ExtendJoinSelectCount;
import com.opensource.component.query.method.ExtendJoinSelectList;
import com.opensource.component.query.method.ExtendJoinSelectPage;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;

/**
 * 基于MP增强的SQL注入器，主要
 *
 * @author ZonLen since on 2021/12/18 下午10:51
 * @see DefaultSqlInjector
 */
public class ExtendSqlInjector extends DefaultSqlInjector {

  /**
   * 抽象封装MappedStatement生成mybatis的SQL脚本模版， 包含占位符提供给动态SQL自定义组装
   */
  @Override
  public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
    final List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
    CollectionUtils.emptyIfNull(methodList).addAll(Arrays.asList(
        new ExtendJoinSelectCount(),
        new ExtendJoinSelectList(),
        new ExtendJoinSelectPage(),
        new ClickhouseExtendSelectCount(),
        new ClickhouseExtendSelectList(),
        new ClickhouseExtendSelectPage(),
        new ClickhouseExtendInsertOne(),
        new ClickhouseExtendUpdate(),
        new ClickhouseExtendDelete()
    ));
    return methodList;
  }
}
